﻿namespace ProductStore.Filters
{
    using System;
    using System.IO;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http.Filters;

    public class NotImplExceptionFilterAttribute : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext context)
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;
            var pats = path + "\\NLogs";
            if (!Directory.Exists(pats))
            {
                Directory.CreateDirectory(pats);
            }
            var file = System.IO.Path.Combine(path, "NLogs", DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt");

            System.IO.File.WriteAllText(file, context.Exception.Message);
            System.IO.File.WriteAllText(file, context.Exception.StackTrace);
            //if (context.Exception is NotImplementedException)
            //{
            //    context.Response = new HttpResponseMessage(HttpStatusCode.NotImplemented);
            //}
        }
    }
}